﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smartec.Accounts.Camel.AMS.Model.Entities;
using Smartec.Accounts.Camel.AMS.Model.Facades;

namespace Smartec.Accounts.Camel.AMS.WebApp.Controllers
{
    [Authorize]
    public class NewsController : Controller
    {
        //
        // GET: /News/

        public ActionResult Index()
        {
            List<News> news = NewsFacade.GetAllNews();
            return View(news);
        }

        //
        // GET: /News/Details/5

        public ActionResult Details(int id)
        {
            News news = NewsFacade.GetNewsById(id);
            return View(news);
        }

        //
        // GET: /News/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /News/Create

        [HttpPost]
        public ActionResult Create(News news)
        {
            try
            {
                // TODO: Add insert logic here
                NewsFacade.AddNews(news);
                NewsFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /News/Edit/5
 
        public ActionResult Edit(int id)
        {
            News news = NewsFacade.GetNewsById(id);
            return View(news);
        }

        //
        // POST: /News/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, News news)
        {
            try
            {
                // TODO: Add update logic here
                NewsFacade.UpdateNews(news);
                NewsFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /News/Delete/5
 
        public ActionResult Delete(int id)
        {
            News news = NewsFacade.GetNewsById(id);
            return View(news);
        }

        //
        // POST: /News/Delete/5

        [HttpPost]
        public ActionResult Delete(int id,Banner banner)
        {
            try
            {
                // TODO: Add delete logic here
                NewsFacade.DeleteNewsById(id);
                NewsFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
